import request from '../utils/http.js'

/**
 * 内存聊天API接口
 */
export const memoryChatApi = {
    
    /**
     * 买家联系客服（创建会话）
     * @param {string} buyerId - 买家ID
     * @param {string} shopId - 店铺ID
     */
    contactCustomerService(buyerId, shopId) {
        return request.post('/memory-chat/contact', null, {
            params: { buyerId, shopId }
        })
    },

    /**
     * 获取买家的会话列表
     * @param {string} buyerId - 买家ID
     */
    getBuyerSessions(buyerId) {
        return request.get(`/memory-chat/buyer/sessions/${buyerId}`)
    },

    /**
     * 获取店铺的会话列表
     * @param {string} shopId - 店铺ID
     */
    getShopSessions(shopId) {
        return request.get(`/memory-chat/shop/sessions/${shopId}`)
    },

    /**
     * 发送消息
     * @param {Object} messageData - 消息数据
     */
    sendMessage(messageData) {
        return request.post('/memory-chat/message', messageData)
    },

    /**
     * 获取会话消息列表
     * @param {string} sessionId - 会话ID
     */
    getSessionMessages(sessionId) {
        return request.get(`/memory-chat/messages/${sessionId}`)
    },

    /**
     * 标记消息为已读
     * @param {string} messageId - 消息ID
     * @param {string} readerId - 阅读者ID
     */
    markMessageAsRead(messageId, readerId) {
        return request.put(`/memory-chat/message/${messageId}/read`, null, {
            params: { readerId }
        })
    },

    /**
     * 获取买家未读消息数量
     * @param {string} buyerId - 买家ID
     */
    getBuyerUnreadCount(buyerId) {
        return request.get(`/memory-chat/buyer/unread/${buyerId}`)
    },

    /**
     * 获取店铺未读消息数量
     * @param {string} shopId - 店铺ID
     */
    getShopUnreadCount(shopId) {
        return request.get(`/memory-chat/shop/unread/${shopId}`)
    },

    /**
     * 关闭会话（清理内存数据）
     * @param {string} sessionId - 会话ID
     */
    closeSession(sessionId) {
        return request.delete(`/memory-chat/session/${sessionId}`)
    }
}